#ifndef __HTTP_PROT_METHOD_H_
#define __HTTP_PROT_METHOD_H_

#include <string.h>


namespace httpprot
{
	enum Method
	{
		METHOD_OPTIONS,
		METHOD_GET,
		METHOD_POST,
		METHOD_HEAD,
		METHOD_PUT,
		METHOD_PATCH,
		METHOD_DELETE,
		METHOD_TRACE,
		METHOD_LINK,
		METHOD_UNLINK,
		METHOD_CONNECT
	};

	inline
	unsigned int GetNumMethods( )
	{
		return 11;
	}

	inline
	const char * GetMethodString( Method method )
	{
		const char * methodToString[ ] =
		{
			"OPTIONS", // METHOD_OPTIONS
			"GET", // METHOD_GET
			"POST", // METHOD_POST
			"HEAD", // METHOD_HEAD
			"PUT", // METHOD_PUT
			"PATCH", // METHOD_PATCH
			"DELETE", // METHOD_DELETE
			"TRACE", // METHOD_TRACE
			"LINK", // METHOD_LINK
			"UNLINK", // METHOD_UNLINK
			"CONNECT" // METHOD_CONNECT
		};

		return methodToString[ method ];
	}

	inline
	bool GetMethodByString( const char * methodString, Method& methodOut )
	{
		for( unsigned int i = 0; i < GetNumMethods( ); ++i )
		{
			Method method = (Method) i;
			if( strcmp( methodString, GetMethodString( method ) ) == 0 )
			{
				methodOut = method;
				return true;
			}
		}

		return false;
	}

	inline
	bool GetMethodByString( const std::string& methodString, Method& methodOut )
	{
		for( unsigned int i = 0; i < GetNumMethods( ); ++i )
		{
			Method method = (Method) i;
			if( methodString == GetMethodString( method ) )
			{
				methodOut = method;
				return true;
			}
		}

		return false;
	}
};

#endif